<?php
if(!defined('IN_WOGU')) {
    exit('Access Denied');
}

Loader::loadClass('Model');

class BlockModel extends Model
{
    protected $_table = 'block';

    public function addBlock($data) {
        return $this->insert($data, true);
    }
    
    public function getBlock($where) {
        $block = $this->getOne($where);
        if($block) {
            $block['block_data'] = unserialize($block['block_data']);
        }
        
        return $block;
    }
    
    public function deleteBlock($id) {
        $this->delete(array('id' => $id));
    }
    
    public function updateBlock($data, $where) {
        return $this->update($data, $where);
    }
    
    public function listBlocks($where, $page = 1, $perpage = 30, $order = 'id ASC') {
        Loader::loadClass('Page');
        return $this->listInfo($where, $page, $perpage, $order, '');
    }
    
    public function getBlocks($where = '', $data = '*') {
        return $this->select($where, $data, '', 'id ASC', '', 'id');
    }
}